/**
 * 用于解析英文识别结果<br>
 *
 * @module ChiVoxSDK/score
 * @author Don Li <kai.li@chivox.com>
 * @licence
 * Copyright (c) 2017 - 2020 ChiVox Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * EnSentRec 类，用于解析英文识别结果<br>
 * 英文识别结果类
 */
class EnSentRec {
    constructor(data) { this.data = data; }

    /**
     * 获得用户设置的评分参数（部分参数经过了过滤处理）
     */
    getParams() { return this.data.params; }

    /**
     * 获得本次评分的录音id。<br>
     * 在startRecord的时候，服务器生成的一个唯一的id，并回传给客户端
     */
    getRecordId() { return this.data.recordId; }

    /**
     * 获得本次请求的录音文件地址
     * @return {string}
     */
    getAudioUrl() { return this.data.audioUrl; }

    /**
     * 本次的识别结果置信度
     * @return {int}
     */
    getConf() { return this.data.result.conf; }

    /**
     * 本次的识别结果
     * @return {int}
     */
    getRec() { return this.data.result.rec; }

    /**
     * 判断是否识别错误
     * @return {boolean}
     */
    hasError() {
        return
            (
             typeof this.data.result == 'undefined' ||
             typeof this.data.result.err != 'undefined' ||
             typeof this.data.result.error != 'undefined' ||
             typeof this.data.result.errID != 'undefined'
            );
    }

    /**
     * 获得错误码。如果不存在错误，则无返回值。
     * @return {int}
     */
    getErrorCode() {
        if (typeof this.data.result != 'undefined' && typeof this.data.result.errID != 'undefined')
            return this.data.result.errID;
        else if (typeof this.data.result.error != 'undefined')
            return this.data.result.error;
    }
}

export default EnSentRec
